package com.videoaggre.zcl.ui.adapter

import android.view.ViewGroup
import com.videoaggre.zcl.bean.AgefansItem
import com.videoaggre.zcl.common.changeVisibility
import com.videoaggre.zcl.databinding.AgefansItemManBinding
import com.videoaggre.zcl.databinding.AgefansItemSearchBinding
import com.videoaggre.zcl.ui.activity.agefans.AgefansDetailsActivity
import com.videoaggre.zcl.ui.activity.agefans.AgefansDetailsDescAdapter
import com.videoaggre.zcl.utils.FullyLinearLayoutManager
import com.videoaggre.zcl.utils.GlideUtils

class AgefansItemAdapter : BaseRecyclerAdapter<BaseViewHolder<AgefansItemManBinding>, AgefansItem>() {
    override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(AgefansItemManBinding.inflate(getLayoutInflate(parent.context), parent, false))
    override fun onBindViewHolder(holder: BaseViewHolder<AgefansItemManBinding>, bean: AgefansItem, position: Int) {
        holder.mViewBinding.run {
            bean.run {
                GlideUtils.intoRoundedCorners(ivCover.context, cover, ivCover, roundingRadius = 2)
                tvName.text = name
                tvTitle.changeVisibility = title.isNotEmpty()
                tvTitle.text = title
                root.setOnClickListener { AgefansDetailsActivity.open(it.context, getItem(position).link) }
            }
        }
    }
}

class AgefansSearchItemAdapter : BaseRecyclerAdapter<BaseViewHolder<AgefansItemSearchBinding>, AgefansItem>() {
    override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(AgefansItemSearchBinding.inflate(getLayoutInflate(parent.context), parent, false))
    override fun onBindViewHolder(holder: BaseViewHolder<AgefansItemSearchBinding>, bean: AgefansItem, position: Int) {
        holder.mViewBinding.run {
            bean.run {
                GlideUtils.intoRoundedCorners(ivCover.context, cover, ivCover, roundingRadius = 2)
                tvTitle.text = title
                tvName.text = name
                val mAgefansDetailsDescAdapter: AgefansDetailsDescAdapter
                if (rvDesc.adapter == null) {
                    mAgefansDetailsDescAdapter = AgefansDetailsDescAdapter()
                    rvDesc.adapter = mAgefansDetailsDescAdapter
                    rvDesc.layoutManager = FullyLinearLayoutManager(rvDesc.context)
                } else {
                    mAgefansDetailsDescAdapter = rvDesc.adapter as AgefansDetailsDescAdapter
                }
                mAgefansDetailsDescAdapter.datas = tags
                mAgefansDetailsDescAdapter.notifyDataSetChanged()
                viewClick.setOnClickListener { AgefansDetailsActivity.open(it.context, getItem(position).link) }
            }
        }
    }
}